<template>
  <div class="common-layout">
    <el-container>
      <el-header class="header-container custom-header">
        <span>欢迎{{ username }}</span>
        <div class="header-title">
          <h2>工厂配件管理系统</h2>
          <p>高效管理，贴心服务</p>
        </div>
        <div class="header-actions">
          <el-link type="primary" href="#" class="logout-link" @click="logout">退出登录</el-link>
        </div>
      </el-header>
      <el-container>
        <el-aside>
          <el-menu active-text-color="#ffd04b" background-color="#545c64" class="el-menu-vertical-demo"
            default-active="/index" text-color="#fff" @select="toPage">
            <el-menu-item index="/index">
              <el-icon>
                  <HomeFilled />
                </el-icon>
              <span>后台首页</span>
            </el-menu-item>
            <el-sub-menu index="1">
              <template #title>
                <el-icon><UserFilled /></el-icon>
                <span>管理员页面</span>
              </template>
              <el-menu-item index="/dept">员工部门管理</el-menu-item>
              <el-menu-item index="/own">设备管理</el-menu-item>
                <el-menu-item index="/peijian">配件管理</el-menu-item>
              <el-menu-item index="/reap">维修人员管理</el-menu-item>
              <el-menu-item index="/repairTask">维修事件管理</el-menu-item>
            </el-sub-menu>
          </el-menu>
        </el-aside>
        <el-main>
          <RouterView />
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script setup>
import { RouterView, RouterLink } from 'vue-router'
import router from '@/router'
import { ref } from 'vue'
import adminApi from '@/api/adminApi';
import { useTokenStore } from '@/stores/token';
import { ElMessage } from 'element-plus';
const username = ref('');
const tokenStore = useTokenStore();
function toPage(indexPath) {
  // 编程式导航
  router.push(indexPath)
}
function getLoginInfo(){
  adminApi.getLoginInfo()
    .then(resp =>{
      username.value = resp.data.username;
    });
}
getLoginInfo();
function logout() {
  ElMessage({
    message: '退出成功',
    type: 'success',
    duration: 500,
    onClose: () => {
      tokenStore.$reset();
      // 跳转
      router.push('/chooseLogin');
    }
  });
}
</script>

<style>
.custom-header {
  background-color: #5c545488;
  color: #333;
  padding: 15px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.custom-header.header-title h2 {
  font-size: 24px;
  margin: 0;
}

.custom-header.header-title p {
  font-size: 14px;
  margin: 5px 0 0;
}

.logout-link {
  font-size: 16px;
  padding: 8px 15px;
  border-radius: 25px;
  background-color: #f8f9fa;
  color: #333;
  transition: all 0.3s ease;
  border: 2px solid #e9ecef;
  cursor: pointer;
  position: relative;
  z-index: 1;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.logout-link:hover {
  background-color: #e9ecef;
  border-color: #dee2e6;
  transform: translateY(-2px);
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.15);
}

.logout-link::before {
  content: "";
  position: absolute;
  top: 0;
  left: -10px;
  width: 0;
  height: 100%;
  background-color: rgba(255, 255, 255, 0.2);
  transition: width 0.3s ease;
  z-index: -1;
}

.logout-link:hover::before {
  width: 10px;
}

</style>